﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class sword_control : MonoBehaviour
{
    // 父物体
    private GameObject father;
    // 移动速度
    private float speed = 7;
    // 偏离父物体的距离
    float pos = 0;

    void Start() {
        father = gameObject.transform.parent.gameObject;
    }
    // Update is called once per frame
    void Update()
    {
        pos = gameObject.transform.position.y - father.transform.position.y;
        if(pos < 8)
        {
            gameObject.transform.position = new Vector3(gameObject.transform.position.x,
                                        gameObject.transform.position.y+speed*Time.deltaTime,gameObject.transform.position.z);
        }
        else
        {
            gameObject.transform.position = new Vector3(gameObject.transform.position.x,
                                        father.transform.position.y-3f,gameObject.transform.position.z);
        }
        
        
    }
}
